package com.gitee.wsl.service.task.listener

import com.gitee.wsl.service.task.scope.TaskScope

class ComposeTaskListener<SCOPE: TaskScope>(
    vararg var adapters: TaskListener<SCOPE>
) : TaskListener<SCOPE> {

    override fun onPending(pendingFun: SCOPE.() -> Unit): TaskListener<SCOPE> {
        return this
    }

    override fun onConnect(connectFun: SCOPE.() -> Unit): TaskListener<SCOPE> {
        return this
    }

    override fun onProgress(progressFun: SCOPE.() -> Unit): TaskListener<SCOPE> {
        return this
    }

    override fun onRetry(retryFun: SCOPE.() -> Unit): TaskListener<SCOPE> {
        return this
    }

    override fun onPaused(pausedFun: SCOPE.() -> Unit): TaskListener<SCOPE> {
        return this
    }

    override fun onError(errorFun: SCOPE.() -> Unit): TaskListener<SCOPE> {
        return this
    }

    override fun onCompleted(completeFun: SCOPE.() -> Unit): TaskListener<SCOPE> {
        return this
    }

    override fun onCancel(cancelFun: SCOPE.() -> Unit): TaskListener<SCOPE> {
        return this
    }

    override fun onDelete(deleteFun: SCOPE.() -> Unit): TaskListener<SCOPE> {
        return this
    }

    override fun warpAdapter(adapter: AbstractTaskListener<SCOPE>) {
    }

    override fun firePending(scope: SCOPE) {
        adapters.forEach {
            it.firePending(scope)
        }
    }

    override fun fireConnect(scope: SCOPE) {
        adapters.forEach {
            it.fireConnect(scope)
        }
    }

    override fun fireProgress(scope: SCOPE) {
        adapters.forEach {
            it.fireProgress(scope)
        }
    }

    override fun fireRetry(scope: SCOPE) {
        adapters.forEach {
            it.fireRetry(scope)
        }
    }

    override fun firePaused(scope: SCOPE) {
        adapters.forEach {
            it.firePaused(scope)
        }
    }

    override fun fireError(scope: SCOPE) {
        adapters.forEach {
            it.fireError(scope)
        }
    }

    override fun fireCompleted(scope: SCOPE) {
        adapters.forEach {
            it.fireCompleted(scope)
        }
    }

    override fun fireCancel(scope: SCOPE) {
        adapters.forEach {
            it.fireCancel(scope)
        }
    }

    override fun fireDelete(scope: SCOPE) {
        adapters.forEach {
            it.fireDelete(scope)
        }
    }

}